<template>
	<view class="home-container">
		<!-- 主标题 -->
		<view class="main-title">生产管理系统</view>
		
		<!-- 功能卡片网格 -->
		<view class="card-grid">
			<!-- 报工管理 -->
			<view class="function-card" @click="navigateTo('/pages/gangben/workPage')">
				<view class="card-icon clipboard-icon">
					<view class="icon-clipboard"></view>
				</view>
				<text class="card-title">报工管理</text>
				<text class="card-subtitle">生产任务报工处理</text>
			</view>
			
			<!-- 设备安灯 -->
			<view class="function-card" @click="navigateTo('/pages/gangben/shebeiPage')">
				<view class="card-icon red-circle-icon">
					<view class="icon-circle"></view>
				</view>
				<text class="card-title">设备安灯</text>
				<text class="card-subtitle">设备状态与报警</text>
			</view>
			
			<!-- 安灯检修 -->
			<view class="function-card" @click="navigateTo('/pages/gangben/andonMaintenance')">
				<view class="card-icon wrench-icon">
					<view class="icon-wrench"></view>
				</view>
				<text class="card-title">安灯检修</text>
				<text class="card-subtitle">安灯维修处理</text>
			</view>
		</view>
		
		<!-- 底部信息栏 -->
		<view class="footer-info">
			<text class="operator-info">操作人: {{ operatorName }}</text>
			<text class="version-info">版本号: {{ version }}</text>
			<view class="logout-btn" @click="handleLogout">退出登录</view>
		</view>
	</view>
</template>

<script>
export default {
  data() {
    return {
			operatorName: '手机测试',
			version: 'v1.0.3'
		}
	},
	onLoad() {
		// 获取操作人信息
		const userInfo = uni.getStorageSync('info');
		if (userInfo && userInfo.realName) {
			this.operatorName = userInfo.realName;
		}
	},
  methods: {
		// 路由跳转
		navigateTo(url) {
			uni.navigateTo({
				url: url,
				fail: (err) => {
					console.error('导航失败:', err);
					// 如果 navigateTo 失败，尝试使用 reLaunch
					uni.reLaunch({
						url: url
					});
				}
			});
		},
		// 退出登录
		handleLogout() {
			uni.showModal({
				title: '提示',
				content: '确定要退出登录吗？',
				success: (res) => {
					if (res.confirm) {
						// 清除登录信息
						uni.removeStorageSync('token');
						uni.removeStorageSync('info');
						// 跳转到登录页
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}
				}
			});
		}
  }
}
</script>

<style scoped>
.home-container {
	width: 100%;
	min-height: 100vh;
	background-color: #f5f5f5;
  padding: 15px;
  display: flex;
  flex-direction: column;
	box-sizing: border-box;
}

.main-title {
	width: 100%;
	text-align: center;
	font-size: 24px;
  font-weight: bold;
	color: #333333;
	margin-top: 30px;
	margin-bottom: 40px;
}

.card-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
  gap: 12px;
	flex: 1;
	padding: 0;
	margin-bottom: 20px;
	width: 100%;
}

.function-card {
	background-color: #ffffff;
	border-radius: 10px;
	padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
	justify-content: center;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
	transition: transform 0.2s, box-shadow 0.2s;
}

.function-card:active {
	transform: scale(0.98);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.card-icon {
	width: 48px;
	height: 48px;
  display: flex;
  align-items: center;
	justify-content: center;
	margin-bottom: 10px;
}

.clipboard-icon {
	background-color: #e3f2fd;
	border-radius: 8px;
}

.red-circle-icon {
	background-color: #ffebee;
	border-radius: 8px;
}

.wrench-icon {
	background-color: #e3f2fd;
	border-radius: 8px;
}

/* 剪贴板图标 */
.icon-clipboard {
	width: 26px;
	height: 26px;
	background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
	border-radius: 4px;
  position: relative;
}

.icon-clipboard::before {
	content: '';
  position: absolute;
	top: 3px;
  left: 50%;
	transform: translateX(-50%);
	width: 18px;
	height: 2px;
	background-color: #ffffff;
	border-radius: 1px;
}

.icon-clipboard::after {
	content: '';
  position: absolute;
	top: 8px;
  left: 50%;
	transform: translateX(-50%);
	width: 18px;
	height: 2px;
	background-color: #ffffff;
	border-radius: 1px;
}

/* 红色圆形图标 */
.icon-circle {
	width: 26px;
	height: 26px;
	background-color: #f44336;
	border-radius: 50%;
}

/* 扳手图标 */
.icon-wrench {
	width: 26px;
	height: 26px;
	position: relative;
}

.icon-wrench::before {
	content: '';
  position: absolute;
  top: 50%;
  left: 50%;
	transform: translate(-50%, -50%) rotate(45deg);
	width: 20px;
	height: 4px;
	background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
	border-radius: 2px;
}

.icon-wrench::after {
	content: '';
  position: absolute;
  top: 50%;
	left: 50%;
  transform: translate(-50%, -50%);
	width: 8px;
	height: 8px;
	border: 3px solid #64b5f6;
	border-top-color: transparent;
	border-right-color: transparent;
  border-radius: 50%;
}

.card-title {
	font-size: 15px;
	font-weight: bold;
	color: #333333;
	margin-bottom: 5px;
	text-align: center;
}

.card-subtitle {
	font-size: 11px;
	color: #999999;
	text-align: center;
	line-height: 1.4;
	padding: 0 3px;
}

.footer-info {
	width: 100%;
	padding: 10px 12px;
	display: flex;
	flex-direction: row;
	align-items: center;
	margin-top: auto;
	background-color: #ffffff;
	flex-wrap: nowrap;
	box-sizing: border-box;
}

.operator-info {
	font-size: 12px;
	color: #333333;
	flex: 0 0 auto;
	white-space: nowrap;
}

.version-info {
	font-size: 12px;
	color: #333333;
	flex: 1;
	text-align: center;
	white-space: nowrap;
}

.logout-btn {
	background-color: #ff4444;
	color: #ffffff;
	border: none;
	border-radius: 6px;
	padding: 7px 16px;
	font-size: 12px;
  text-align: center;
	transition: background-color 0.2s;
	flex: 0 0 auto;
	cursor: pointer;
	white-space: nowrap;
	line-height: 1.5;
}

.logout-btn:active {
	background-color: #cc0000;
	opacity: 0.8;
}

/* 适配不同屏幕尺寸 */
@media screen and (max-width: 375px) {
	.home-container {
		padding: 10px;
	}
	
	.main-title {
		font-size: 22px;
		margin-top: 20px;
		margin-bottom: 30px;
	}
	
	.card-grid {
		gap: 12px;
		padding: 0;
	}
	
	.function-card {
		padding: 18px 12px;
		min-height: 120px;
	}
	
	.card-icon {
		width: 45px;
		height: 45px;
		margin-bottom: 10px;
	}
	
	.icon-clipboard,
	.icon-circle,
	.icon-wrench {
		width: 24px;
		height: 24px;
	}
	
	.card-title {
		font-size: 15px;
		margin-bottom: 5px;
	}
	
	.card-subtitle {
		font-size: 11px;
	}
	
	.footer-info {
		padding: 10px 12px;
		gap: 8px;
	}
	
	.operator-info,
	.version-info,
	.logout-btn {
		font-size: 12px;
	}
	
	.logout-btn {
		padding: 6px 16px;
	}
}
</style>
